﻿//============================================================================================
/*
 * @brief 注册系统组件。
 * 
 *********************************************************************************************/

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace ProjectTemplate;

public static class InitializationServiceCollectionExtensions
{
    public static IServiceCollection ConfigureCore(this IServiceCollection services, IConfiguration configuration)
    {
        // 配置文件大小限制
        services.Configure<FormOptions>(options =>
        {
            options.ValueLengthLimit = int.MaxValue;
            options.MultipartBodyLengthLimit = int.MaxValue;// 60000000;
            options.MultipartHeadersLengthLimit = int.MaxValue;
        });

        // 允许同步读取IO流，否则无法同步读取 Request.Body。
        services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true);
        services.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);

        return services;
    }
}